#!/bin/bash

if [ "$SUBSHELL" = "1" ]; then
    echo subshell call $BASHPID
    exit
fi

cnt=0
function printPID()
{
    echo function $BASHPID
    ((cnt++))
}

echo local $BASHPID
echo after local, cnt=$cnt
printPID
echo after call, cnt=$cnt
printPID &
sleep 1
echo after async call, cnt=$cnt
echo 1 | printPID
echo after pipe, cnt=$cnt
(printPID)
echo after subshell cnt=$cnt
SUBSHELL=1 $0
SUBSHELL=1 source $0
